﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace SocialCee.Authorization
{
    /// <summary>
    /// TODO
    /// Implement other overload method
    /// </summary>
    public class RoleManager
    {
        /// <summary>
        /// Create user role
        /// </summary>
        /// <param name="roleName"></param>
        /// <returns></returns>
        public static bool CreateRole(string roleName)
        {
            if (!Roles.RoleExists(roleName))
                Roles.CreateRole(roleName);

            return Roles.RoleExists(roleName);
        }

        /// <summary>
        /// Check if user is in role
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="roleName"></param>
        /// <returns></returns>
        public static bool IsInRole(string userName, string roleName)
        {
            if (Roles.RoleExists(roleName))
                return Roles.IsUserInRole(userName, roleName);

            return false;
        }

        public static bool AssignUserToRole(string userName, string roleName)
        {
            if (CreateRole(roleName))
            {
                Roles.AddUserToRole(userName, roleName);
            }

            return Roles.IsUserInRole(userName, roleName);
        }
    }
}
